package com.web.controller;

import com.web.entity.Product;
import com.web.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @RequestMapping("/list")
    public List<Product> list() {
        return productService.findAll();
    }

    @RequestMapping("/get")
    public Product get(Integer id) {
        return productService.findById(id);
    }

    @RequestMapping("/add")
    public String add(Product product) {
        productService.save(product);
        return "success";
    }

    @RequestMapping("/update")
    public String update(Product product) {
        productService.update(product);
        return "success";
    }

    @RequestMapping("/delete")
    public String delete(Integer id) {
        productService.delete(id);
        return "success";
    }


}
